package com.wiser.ohosservice;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.event.notification.NotificationRequest;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.rpc.IRemoteObject;

public class ServiceAbility extends Ability {

    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "生命周期：ServiceAbility");

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        HiLog.error(LABEL,"onStart");
    }

    @Override
    protected void onCommand(Intent intent, boolean restart, int startId) {
        super.onCommand(intent, restart, startId);
        // 前台服务
        NotificationRequest request = new NotificationRequest(1000);
        NotificationRequest.NotificationNormalContent content = new NotificationRequest.NotificationNormalContent();
        content.setTitle("前台服务标题");
        content.setText("前台服务内容");
        NotificationRequest.NotificationContent notificationContent = new NotificationRequest.NotificationContent(content);
        request.setContent(notificationContent);
        keepBackgroundRunning(1000,request);
        HiLog.error(LABEL,"onCommand");
    }

    @Override
    protected IRemoteObject onConnect(Intent intent) {
        HiLog.error(LABEL,"onConnect");
        return super.onConnect(intent);
    }

    @Override
    protected void onDisconnect(Intent intent) {
        super.onDisconnect(intent);
        HiLog.error(LABEL,"onDisconnect");
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        HiLog.error(LABEL,"onBackground");
    }

    @Override
    protected void onStop() {
        super.onStop();
        cancelBackgroundRunning();
        HiLog.error(LABEL,"onStop");
    }
}
